<?php 

global $wpdb;
global $post;

$results = $wpdb->get_results('SELECT * FROM wp_wptravel WHERE post_ID = ' . $post->ID);

if (count($results) > 0){
?>
<script type="text/javascript">
	jQuery(document).ready(function() {
<?php foreach($results as $result) { ?>
		scheduledDates.push({startDate:     "<?php echo $result->startDate;?>",
							 endDate:       "<?php echo $result->endDate;?>",
							 price:         "<?php echo $result->price;?>",
							 currency:      "<?php echo $result->currency;?>",
							 accommodation: "<?php echo $result->accommodation;?>",
							 air:           <?php echo ($result->airIncluded == 'y'?'true':'false');?>,
							 closed:        <?php echo ($result->closed == 'y'?'true':'false');?>,
							 guaranteed:    <?php echo ($result->guaranteed == 'y'?'true':'false');?>,
							 limited:       <?php echo ($result->limited == 'y'?'true':'false');?>});
<?php }?>
		renderScheduledDates();
	});
</script>
<?php 
}

echo '<input type="hidden" name="wptravel_noncename" id="wptravel_noncename" value="' . 
    wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
echo '<input type="hidden" id="wptravel_startDate" name="wptravel_startDate" />';
echo '<input type="hidden" id="wptravel_endDate" name="wptravel_endDate" />';
    
echo '<label for="wptravel_startDate">' . __("Start Date", 'myplugin_textdomain' ) . '</label> ';
echo '<input type="text" id="wptravel_DstartDate" name="wptravel_DstartDate" value="" size="10" /><br />';

echo '<label for="wptravel_endDate">' . __("End Date", 'myplugin_textdomain' ) . '</label> ';
echo '<input type="text" id="wptravel_DendDate" name="wptravel_DendDate" value="" size="10" /><br />';

echo '<label for="wptravel_price">' . __("Price", 'myplugin_textdomain' ) . '</label> ';
echo '$ <input type="text" id="wptravel_price" name="wptravel_price" value="" size="10" /><br />';

echo '<label for="wptravel_currency">' . __("Currency", 'myplugin_textdomain' ) . '</label> ';
echo '<select id="wptravel_currency" name="wptravel_currency"><option value="CDN">CDN</option><option value="USD">USD</option><option value="EUR">EUR</option></select><br />';

echo '<label for="wptravel_accommodation">' . __("Accommodation", 'myplugin_textdomain' ) . '</label> ';
echo '<select id="wptravel_accommodation" name="wptravel_accommodation"><option value="single">Single</option><option value="double">Double</option><option value="triple">Triple</option><option value="quad">Quad</option><option value="group">Group</option></select><br />';

echo '<input type="checkbox" id="wptravel_air" name="wptravel_air" value="y" />';
echo '<label for="wptravel_air">' . __("Air Included", 'myplugin_textdomain' ) . '</label><br />';

echo '<input type="checkbox" id="wptravel_closed" name="wptravel_closed" value="y" />';
echo '<label for="wptravel_closed">' . __("Closed", 'myplugin_textdomain' ) . '</label><br />';

echo '<input type="checkbox" id="wptravel_guaranteed" name="wptravel_guaranteed" value="y" />';
echo '<label for="wptravel_guaranteed">' . __("Guaranteed", 'myplugin_textdomain' ) . '</label><br />';

echo '<input type="checkbox" id="wptravel_limitedAvailability" name="wptravel_limitedAvailability" value="y" />';
echo '<label for="wptravel_limitedAvailability">' . __("Limited Availability", 'myplugin_textdomain' ) . '</label><br />';

echo '<input type="button" id="wptravel_addScheduleButton" value="Add Schedule" class="button" />';
?>

<div>
 NOTE: By default, the dates are added at the beginning of the post.
 Add <em>[wptravel_dates]</em> to your post to place it anywhere you like.
</div>

<div>
	<h1>Scheduled Dates</h1>
	<div id="wptravel_scheduledDates">
	</div>
</div>

<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery("#wptravel_DstartDate").datepicker({ minDate: 0, altField: '#wptravel_startDate', altFormat: 'yy-mm-dd' });
		jQuery("#wptravel_DendDate").datepicker({ minDate: 0, altField: '#wptravel_endDate', altFormat: 'yy-mm-dd' });
	});
</script>
